#! /usr/bin/perl

use strict;
use ReconReport;
use Getopt::Std;
use Net::Domain  qw(hostname);



our $opt_b;
getopts('b:');

exit 1 if  $opt_b !~ /\d{6}(_\d{6}){2}/; 


        # run this script in the MLPROD TMP dir.
        chdir("$ENV{MLPROD_HOME}/tmp");

        #---------------------------------------------------
        # In srv3, PGHOST will be set by mlprodbatch daemon,
        # this block of code will not be excuted.
        #
        # In devlop box, this block of code will be executed
        #----------------------------------------------------
        if( ! exists $ENV{'PGHOST'} ) {
                my $host = hostname() ;
                my $alias = (gethostbyname($host))[1];
                my @aliases = split(/\s+/, $alias);
                my @dbhosts = grep(/^hdb-/, @aliases);
                if ( @dbhosts > 0 ) {
                        $ENV{'PGHOST'} = shift @dbhosts;
                } else {
                        $ENV{'PGHOST'} = shift @aliases;
                }
        }


        #-------------------------------------
        # Find out expected files  
        #  $ENV{MLPROD_HOME}/config/.mlprivate.cfg ;
        #------------------------------------
        my $g_dbschema = "payorintel";
        my $g_dbbasename="$ENV{USER}" || "mlprod" ;
        my $g_dbname=$g_dbbasename . "_db";
        my $g_dbuser=$g_dbschema . "_" . $g_dbbasename . "_u";

	my $report_obj  = ReconReport->new();                                
	my $dbh = $report_obj->connect_db($g_dbname, $g_dbuser);
	if ( $dbh ) {
		$report_obj->create_and_deliver_report("recon", $opt_b);
	}

        exit 0;

